<template>
  <div class="dashboard-container">
    <component :is="currentRole" />
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import adminDashboard from './admin'
import procurementDashboard from './procurement'
import procurementFinanceDashboard from './procurement-finance'
import cashierDashboard from './procurement-cashier'
import logisticsDashboard from './logistics'
import logisticsFinanceDashboard from './logistics-finance'
import customerService from './customer-service'
import customerServiceSuper from './customer-service-super'

export default {
  name: 'Dashboard',
  components: { adminDashboard, procurementDashboard, logisticsDashboard, logisticsFinanceDashboard, procurementFinanceDashboard, cashierDashboard, customerService, customerServiceSuper },
  data() {
    return {
      currentRole: 'adminDashboard'
    }
  },
  computed: {
    ...mapGetters([
      'roles'
    ])
  },
  created() {
    console.log('登录权限信息----')
    console.log(this.$store.getters.token)
    console.log(this.$store.state.settings.wmsConf)
    const loginDeptId = this.$store.getters.token.deptId
    const loginDutyId = this.$store.getters.token.dutyId
    const configLogisticsDeptId = this.$store.state.settings.wmsConf.logistics.deptId // 物流部门id
    const configPurchaseDeptId = this.$store.state.settings.wmsConf.purchase.deptId // 采购部门id
    const configCustomerDeptId = this.$store.state.settings.wmsConf.service.deptId // 客服部部门id

    if (this.$store.getters.token.deptId === null) { // 超级管理员
      this.currentRole = 'adminDashboard'
    } else if (loginDeptId === configLogisticsDeptId && loginDutyId === this.$store.state.settings.wmsConf.logistics.dutyId[0]) { // 物流主管
      this.currentRole = 'logisticsDashboard'
    } else if (loginDeptId === configLogisticsDeptId && loginDutyId === this.$store.state.settings.wmsConf.logistics.dutyId[2]) { // 物流财务
      this.currentRole = 'logisticsFinanceDashboard'
    } else if (loginDeptId === configPurchaseDeptId && loginDutyId === this.$store.state.settings.wmsConf.purchase.dutyId[0]) { // 采购主管
      this.currentRole = 'procurementDashboard'
    } else if (loginDeptId === configPurchaseDeptId && loginDutyId === this.$store.state.settings.wmsConf.purchase.dutyId[3]) { // 采购财务
      this.currentRole = 'procurementFinanceDashboard'
    } else if (loginDeptId === configPurchaseDeptId && loginDutyId === this.$store.state.settings.wmsConf.purchase.dutyId[4]) { // 采购出纳
      this.currentRole = 'cashierDashboard'
    } else if (loginDeptId === configCustomerDeptId && loginDutyId === this.$store.state.settings.wmsConf.service.dutyId[0]) { // 客服主管
      this.currentRole = 'customerServiceSuper'
    } else if (loginDeptId === configCustomerDeptId && loginDutyId === this.$store.state.settings.wmsConf.service.dutyId[1]) { // 客服
      this.currentRole = 'customerService'
    }
    // if (!this.roles.includes('admin')) {
    //   this.currentRole = 'editorDashboard'
    // }
  }
}
</script>

